package com.example.dishit.controller.editpref;

import com.example.dishit.model.editpref.PreferenceData;
import com.example.dishit.model.editpref.PreferenceDatabaseFactory;
import com.example.dishit.view.alert.AlertView;
import com.example.dishit.view.editpref.EditPrefActivity;

public class EditPrefController implements IEditPrefController {
    private final EditPrefActivity view;
    
    public EditPrefController(EditPrefActivity view) {
        this.view = view;
    }
    
    public void cancel() {
        view.finish();
    }
    
    public void savePreferences(PreferenceData data) {
        // Store the new data.
        PreferenceDatabaseFactory.instance().storePreferences(data);
        
        // Enable/disable alerts.
        AlertView.setEnabled(data.isAlertsFromDishersEnabled());
    }
    
    public PreferenceData getPreferences() {
        return PreferenceDatabaseFactory.instance().getPreferences();
    }
}
